import pymysql
from urlTestDemo.baseUrlTest import base_request_test
from urlTestDemo.redisUtils import initRedisUtils

redisUtil = initRedisUtils()
db_host = redisUtil.get("visa_db_host")
db_port = redisUtil.get("visa_db_port")
db_user = redisUtil.get("visa_db_user")
db_psw = redisUtil.get("visa_db_password")
db_name = redisUtil.get("visa_db_name")
pre_url = redisUtil.get("visa_pre_url")
search_sql = redisUtil.get("visa_search_sql")

conn = pymysql.connect(host=db_host, port=int(db_port), user=db_user, passwd=db_psw,db=db_name)
cur = conn.cursor()
cur.execute(search_sql)

def findAllOnlineVisaProductUrl():
    visaPreUrl = pre_url
    priductIdList = []
    for row in cur.fetchall():
        id = row[0]
        priductIdList.append(visaPreUrl+str(id)+'.html')
    cur.close()
    conn.close()
    return priductIdList


# 批量测试 签证组合产品链接
def batchTestVisaUrl():
    allVisaProblemUrlList = []  # 存放签证 问题url
    allOnlineVisaUrls = findAllOnlineVisaProductUrl()
    for visaProductUrl in allOnlineVisaUrls:
        base_request_test(visaProductUrl, allVisaProblemUrlList)
    print('签证问题链接列表',allVisaProblemUrlList)
    return allVisaProblemUrlList

